package com.txunda.zhuohired.adapter.user.home;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lidroid.xutils.ViewUtils;
import com.txunda.zhuohired.R;
import com.txunda.zhuohired.bean.user.home.FilterBean;

import java.util.ArrayList;


/**
 * 创建人： Txd_Cjh
 * 创建时间： 2018/2/27 9:18
 * 功能描述：每日新职位adapter
 * 联系方式：jiahuanchen@126.com
 */

public class TodayNewAddressAdapter extends BaseAdapter {

    private Context context;
    private ViewHolder holder;
    private ArrayList<FilterBean.DataBean.AreaListBean> list;

    public TodayNewAddressAdapter(ArrayList<FilterBean.DataBean.AreaListBean> list, Context context) {
        this.context = context;
        this.list = list;
    }

    public void setData(ArrayList<FilterBean.DataBean.AreaListBean> list) {
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    public ArrayList<FilterBean.DataBean.AreaListBean> getList() {
        return list;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        if (view == null) {
            view = LayoutInflater.from(context).inflate(R.layout.item_add_list, null);
            holder = new ViewHolder();
            holder.name = view.findViewById(R.id.tv_item_add_name);
            holder.iv = view.findViewById(R.id.iv_item_add);
            holder.add = view.findViewById(R.id.ll_item_address);
            view.setTag(holder);
            ViewUtils.inject(holder, view);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        holder.name.setText(list.get(i).getRegion_name());
        holder.iv.setImageResource(list.get(i).isSelect() ? R.mipmap.icon_screen_yes : R.mipmap.icon_screen_no);
        holder.add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                list.get(i).setSelect(!list.get(i).isSelect());
                notifyDataSetChanged();
            }
        });
        return view;
    }

    class ViewHolder {
        TextView name;
        ImageView iv;
        LinearLayout add;
    }
}
